
import 'package:flustars/flustars.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/bean/login/LoginDataBean.dart';

///  sp记录数据
class SPHelper{
   static const APP_FIRST="AppFirst";//第一次启动
   static const LOGIN_TOKEN="login_token";//登录 token
   static const LOGIN_PHONE="login_phone";//登录 token
   static const LOGIN_INFO="login_info";//登录 info


   //保存第一次启动
   static void saveAppFirstUp({bool isFirst=true}){
       SpUtil.putBool(APP_FIRST, isFirst);
   }

   //获取第一次启动
   static bool getAppFirstUp(){
     return SpUtil.getBool(APP_FIRST,defValue: false)??false;
   }

   //保存Phone
   static void savePhone(String  phone){
      SpUtil.putString(LOGIN_PHONE, phone);
   }

   //获取Phone
   static String? getPhone(){
      return SpUtil.getString(LOGIN_PHONE);
   }

   //保存token
   static void saveToken(String  token){
      SpUtil.putString(LOGIN_TOKEN, token);
   }

   //获取token
   static String? getToken(){
       return SpUtil.getString(LOGIN_TOKEN);
   }

   //保存登录信息
   static void saveLoginInfo(LoginBean  loginBean){
      var info = loginBean.toJson();
      saveToken(loginBean.token??"");
      SpUtil.putObject(LOGIN_INFO, info);
   }

   //获取登录信息
   static LoginBean getLoginInfo(){
      var object = SpUtil.getObject(LOGIN_INFO);
      Map<String, dynamic> json =( object ?? Map<String, dynamic>()) as Map<String, dynamic>;
      return LoginBean.fromJson(json);
   }
}